{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "c229e3b6-7c7f-4b07-a6e0-72da70d90358",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3341d11a-b72b-4977-a771-b392e3d91696",
   "metadata": {},
   "outputs": [],
   "source": [
    "train_data = pd.read_csv('水泵状态监测与故障诊断挑战赛公开数据/train.csv')\n",
    "test_data = pd.read_csv('水泵状态监测与故障诊断挑战赛公开数据/test.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "5802427c-f1c6-4695-a8d3-5aa6309d4218",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>x0</th>\n",
       "      <th>x1</th>\n",
       "      <th>x2</th>\n",
       "      <th>x3</th>\n",
       "      <th>x4</th>\n",
       "      <th>x5</th>\n",
       "      <th>x6</th>\n",
       "      <th>x7</th>\n",
       "      <th>x8</th>\n",
       "      <th>...</th>\n",
       "      <th>x42</th>\n",
       "      <th>x43</th>\n",
       "      <th>x44</th>\n",
       "      <th>x45</th>\n",
       "      <th>x46</th>\n",
       "      <th>x47</th>\n",
       "      <th>x48</th>\n",
       "      <th>x49</th>\n",
       "      <th>x50</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>2.374884</td>\n",
       "      <td>49.739580</td>\n",
       "      <td>49.956600</td>\n",
       "      <td>44.140625</td>\n",
       "      <td>597.916600</td>\n",
       "      <td>84.390590</td>\n",
       "      <td>13.382520</td>\n",
       "      <td>16.304980</td>\n",
       "      <td>15.769680</td>\n",
       "      <td>...</td>\n",
       "      <td>41.666660</td>\n",
       "      <td>54.108800</td>\n",
       "      <td>40.509260</td>\n",
       "      <td>50.636570</td>\n",
       "      <td>50.636570</td>\n",
       "      <td>162.615700</td>\n",
       "      <td>97.511570</td>\n",
       "      <td>195.601900</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>40.820386</td>\n",
       "      <td>40.733584</td>\n",
       "      <td>39.626887</td>\n",
       "      <td>201.426291</td>\n",
       "      <td>99.999878</td>\n",
       "      <td>10.094722</td>\n",
       "      <td>12.606676</td>\n",
       "      <td>12.646451</td>\n",
       "      <td>...</td>\n",
       "      <td>32.161910</td>\n",
       "      <td>33.492731</td>\n",
       "      <td>33.782084</td>\n",
       "      <td>33.854168</td>\n",
       "      <td>35.011574</td>\n",
       "      <td>33.564817</td>\n",
       "      <td>33.854168</td>\n",
       "      <td>37.905094</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>2.460705</td>\n",
       "      <td>48.792725</td>\n",
       "      <td>51.085070</td>\n",
       "      <td>42.250292</td>\n",
       "      <td>637.352123</td>\n",
       "      <td>81.032885</td>\n",
       "      <td>13.345434</td>\n",
       "      <td>16.098846</td>\n",
       "      <td>15.763010</td>\n",
       "      <td>...</td>\n",
       "      <td>37.945082</td>\n",
       "      <td>35.011570</td>\n",
       "      <td>42.571572</td>\n",
       "      <td>34.281048</td>\n",
       "      <td>45.495901</td>\n",
       "      <td>89.963656</td>\n",
       "      <td>41.742577</td>\n",
       "      <td>174.035795</td>\n",
       "      <td>167.770731</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>0.003935</td>\n",
       "      <td>46.627000</td>\n",
       "      <td>46.515356</td>\n",
       "      <td>42.925346</td>\n",
       "      <td>272.008102</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>11.046010</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>11.103880</td>\n",
       "      <td>...</td>\n",
       "      <td>30.208332</td>\n",
       "      <td>30.671299</td>\n",
       "      <td>30.464729</td>\n",
       "      <td>31.828701</td>\n",
       "      <td>32.118059</td>\n",
       "      <td>34.432869</td>\n",
       "      <td>32.407406</td>\n",
       "      <td>36.747684</td>\n",
       "      <td>36.458331</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>2.449653</td>\n",
       "      <td>45.746520</td>\n",
       "      <td>50.390620</td>\n",
       "      <td>41.710068</td>\n",
       "      <td>642.476800</td>\n",
       "      <td>80.790730</td>\n",
       "      <td>13.614000</td>\n",
       "      <td>15.668400</td>\n",
       "      <td>15.371820</td>\n",
       "      <td>...</td>\n",
       "      <td>36.197910</td>\n",
       "      <td>34.432870</td>\n",
       "      <td>35.011570</td>\n",
       "      <td>37.326389</td>\n",
       "      <td>40.219910</td>\n",
       "      <td>59.027780</td>\n",
       "      <td>41.956020</td>\n",
       "      <td>177.662000</td>\n",
       "      <td>157.407400</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 53 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   id          x0         x1         x2         x3          x4         x5  \\\n",
       "0   0    2.374884  49.739580  49.956600  44.140625  597.916600  84.390590   \n",
       "1   1 -999.000000  40.820386  40.733584  39.626887  201.426291  99.999878   \n",
       "2   2    2.460705  48.792725  51.085070  42.250292  637.352123  81.032885   \n",
       "3   3    0.003935  46.627000  46.515356  42.925346  272.008102   0.000000   \n",
       "4   4    2.449653  45.746520  50.390620  41.710068  642.476800  80.790730   \n",
       "\n",
       "          x6          x7         x8  ...        x42        x43        x44  \\\n",
       "0  13.382520   16.304980  15.769680  ...  41.666660  54.108800  40.509260   \n",
       "1  10.094722   12.606676  12.646451  ...  32.161910  33.492731  33.782084   \n",
       "2  13.345434   16.098846  15.763010  ...  37.945082  35.011570  42.571572   \n",
       "3  11.046010 -999.000000  11.103880  ...  30.208332  30.671299  30.464729   \n",
       "4  13.614000   15.668400  15.371820  ...  36.197910  34.432870  35.011570   \n",
       "\n",
       "         x45        x46         x47        x48         x49         x50  target  \n",
       "0  50.636570  50.636570  162.615700  97.511570  195.601900 -999.000000       0  \n",
       "1  33.854168  35.011574   33.564817  33.854168   37.905094 -999.000000       1  \n",
       "2  34.281048  45.495901   89.963656  41.742577  174.035795  167.770731       0  \n",
       "3  31.828701  32.118059   34.432869  32.407406   36.747684   36.458331       1  \n",
       "4  37.326389  40.219910   59.027780  41.956020  177.662000  157.407400       0  \n",
       "\n",
       "[5 rows x 53 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b6387efe-1170-4f02-9cc3-c9a54aacf554",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>x0</th>\n",
       "      <th>x1</th>\n",
       "      <th>x2</th>\n",
       "      <th>x3</th>\n",
       "      <th>x4</th>\n",
       "      <th>x5</th>\n",
       "      <th>x6</th>\n",
       "      <th>x7</th>\n",
       "      <th>x8</th>\n",
       "      <th>...</th>\n",
       "      <th>x42</th>\n",
       "      <th>x43</th>\n",
       "      <th>x44</th>\n",
       "      <th>x45</th>\n",
       "      <th>x46</th>\n",
       "      <th>x47</th>\n",
       "      <th>x48</th>\n",
       "      <th>x49</th>\n",
       "      <th>x50</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.000000</td>\n",
       "      <td>200000.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>99999.500000</td>\n",
       "      <td>-100.186176</td>\n",
       "      <td>46.611734</td>\n",
       "      <td>50.436184</td>\n",
       "      <td>42.977396</td>\n",
       "      <td>550.496525</td>\n",
       "      <td>68.804077</td>\n",
       "      <td>7.729729</td>\n",
       "      <td>0.147128</td>\n",
       "      <td>1.043607</td>\n",
       "      <td>...</td>\n",
       "      <td>43.330748</td>\n",
       "      <td>39.565152</td>\n",
       "      <td>41.002372</td>\n",
       "      <td>44.577704</td>\n",
       "      <td>42.229553</td>\n",
       "      <td>107.054977</td>\n",
       "      <td>52.044521</td>\n",
       "      <td>176.078498</td>\n",
       "      <td>37.891388</td>\n",
       "      <td>0.15010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>57735.171256</td>\n",
       "      <td>303.477506</td>\n",
       "      <td>27.286260</td>\n",
       "      <td>9.750700</td>\n",
       "      <td>9.175714</td>\n",
       "      <td>186.612042</td>\n",
       "      <td>28.382071</td>\n",
       "      <td>68.766078</td>\n",
       "      <td>122.066271</td>\n",
       "      <td>116.518647</td>\n",
       "      <td>...</td>\n",
       "      <td>20.878400</td>\n",
       "      <td>13.925047</td>\n",
       "      <td>16.075443</td>\n",
       "      <td>19.581130</td>\n",
       "      <td>14.497385</td>\n",
       "      <td>60.468005</td>\n",
       "      <td>19.121217</td>\n",
       "      <td>69.981238</td>\n",
       "      <td>395.868601</td>\n",
       "      <td>0.35717</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>-999.000000</td>\n",
       "      <td>0.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>49999.750000</td>\n",
       "      <td>2.352257</td>\n",
       "      <td>46.440970</td>\n",
       "      <td>49.956600</td>\n",
       "      <td>42.057290</td>\n",
       "      <td>620.601900</td>\n",
       "      <td>71.051100</td>\n",
       "      <td>13.109088</td>\n",
       "      <td>15.642733</td>\n",
       "      <td>15.042600</td>\n",
       "      <td>...</td>\n",
       "      <td>38.439515</td>\n",
       "      <td>35.300930</td>\n",
       "      <td>36.168980</td>\n",
       "      <td>38.703395</td>\n",
       "      <td>37.905094</td>\n",
       "      <td>64.236110</td>\n",
       "      <td>46.006940</td>\n",
       "      <td>161.517805</td>\n",
       "      <td>125.319464</td>\n",
       "      <td>0.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>99999.500000</td>\n",
       "      <td>2.452709</td>\n",
       "      <td>47.916660</td>\n",
       "      <td>51.649300</td>\n",
       "      <td>43.402775</td>\n",
       "      <td>630.560428</td>\n",
       "      <td>76.870485</td>\n",
       "      <td>13.382520</td>\n",
       "      <td>16.068320</td>\n",
       "      <td>15.229613</td>\n",
       "      <td>...</td>\n",
       "      <td>41.927080</td>\n",
       "      <td>38.926839</td>\n",
       "      <td>39.062500</td>\n",
       "      <td>42.374552</td>\n",
       "      <td>41.256844</td>\n",
       "      <td>94.328700</td>\n",
       "      <td>50.347221</td>\n",
       "      <td>190.972200</td>\n",
       "      <td>188.078700</td>\n",
       "      <td>0.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>149999.250000</td>\n",
       "      <td>2.471215</td>\n",
       "      <td>49.131940</td>\n",
       "      <td>52.951390</td>\n",
       "      <td>44.704861</td>\n",
       "      <td>635.959205</td>\n",
       "      <td>81.725503</td>\n",
       "      <td>13.609136</td>\n",
       "      <td>16.178241</td>\n",
       "      <td>15.530960</td>\n",
       "      <td>...</td>\n",
       "      <td>45.572914</td>\n",
       "      <td>42.534720</td>\n",
       "      <td>43.402779</td>\n",
       "      <td>46.875000</td>\n",
       "      <td>45.138890</td>\n",
       "      <td>141.782400</td>\n",
       "      <td>55.711575</td>\n",
       "      <td>217.592600</td>\n",
       "      <td>208.622700</td>\n",
       "      <td>0.00000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>199999.000000</td>\n",
       "      <td>2.549016</td>\n",
       "      <td>55.772570</td>\n",
       "      <td>56.032990</td>\n",
       "      <td>48.220490</td>\n",
       "      <td>800.000000</td>\n",
       "      <td>99.999880</td>\n",
       "      <td>22.251160</td>\n",
       "      <td>23.509840</td>\n",
       "      <td>23.307290</td>\n",
       "      <td>...</td>\n",
       "      <td>408.593700</td>\n",
       "      <td>221.064800</td>\n",
       "      <td>220.196800</td>\n",
       "      <td>320.891200</td>\n",
       "      <td>196.759300</td>\n",
       "      <td>502.314800</td>\n",
       "      <td>323.206000</td>\n",
       "      <td>483.506900</td>\n",
       "      <td>1000.000000</td>\n",
       "      <td>1.00000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 53 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  id             x0             x1             x2  \\\n",
       "count  200000.000000  200000.000000  200000.000000  200000.000000   \n",
       "mean    99999.500000    -100.186176      46.611734      50.436184   \n",
       "std     57735.171256     303.477506      27.286260       9.750700   \n",
       "min         0.000000    -999.000000    -999.000000    -999.000000   \n",
       "25%     49999.750000       2.352257      46.440970      49.956600   \n",
       "50%     99999.500000       2.452709      47.916660      51.649300   \n",
       "75%    149999.250000       2.471215      49.131940      52.951390   \n",
       "max    199999.000000       2.549016      55.772570      56.032990   \n",
       "\n",
       "                  x3             x4             x5             x6  \\\n",
       "count  200000.000000  200000.000000  200000.000000  200000.000000   \n",
       "mean       42.977396     550.496525      68.804077       7.729729   \n",
       "std         9.175714     186.612042      28.382071      68.766078   \n",
       "min      -999.000000    -999.000000    -999.000000    -999.000000   \n",
       "25%        42.057290     620.601900      71.051100      13.109088   \n",
       "50%        43.402775     630.560428      76.870485      13.382520   \n",
       "75%        44.704861     635.959205      81.725503      13.609136   \n",
       "max        48.220490     800.000000      99.999880      22.251160   \n",
       "\n",
       "                  x7             x8  ...            x42            x43  \\\n",
       "count  200000.000000  200000.000000  ...  200000.000000  200000.000000   \n",
       "mean        0.147128       1.043607  ...      43.330748      39.565152   \n",
       "std       122.066271     116.518647  ...      20.878400      13.925047   \n",
       "min      -999.000000    -999.000000  ...    -999.000000    -999.000000   \n",
       "25%        15.642733      15.042600  ...      38.439515      35.300930   \n",
       "50%        16.068320      15.229613  ...      41.927080      38.926839   \n",
       "75%        16.178241      15.530960  ...      45.572914      42.534720   \n",
       "max        23.509840      23.307290  ...     408.593700     221.064800   \n",
       "\n",
       "                 x44            x45            x46            x47  \\\n",
       "count  200000.000000  200000.000000  200000.000000  200000.000000   \n",
       "mean       41.002372      44.577704      42.229553     107.054977   \n",
       "std        16.075443      19.581130      14.497385      60.468005   \n",
       "min      -999.000000    -999.000000    -999.000000    -999.000000   \n",
       "25%        36.168980      38.703395      37.905094      64.236110   \n",
       "50%        39.062500      42.374552      41.256844      94.328700   \n",
       "75%        43.402779      46.875000      45.138890     141.782400   \n",
       "max       220.196800     320.891200     196.759300     502.314800   \n",
       "\n",
       "                 x48            x49            x50        target  \n",
       "count  200000.000000  200000.000000  200000.000000  200000.00000  \n",
       "mean       52.044521     176.078498      37.891388       0.15010  \n",
       "std        19.121217      69.981238     395.868601       0.35717  \n",
       "min      -999.000000    -999.000000    -999.000000       0.00000  \n",
       "25%        46.006940     161.517805     125.319464       0.00000  \n",
       "50%        50.347221     190.972200     188.078700       0.00000  \n",
       "75%        55.711575     217.592600     208.622700       0.00000  \n",
       "max       323.206000     483.506900    1000.000000       1.00000  \n",
       "\n",
       "[8 rows x 53 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "0b80d7b2-a964-472f-b6c9-759453b843b6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "id            0\n",
       "x0        20467\n",
       "x1          134\n",
       "x2           14\n",
       "x3           14\n",
       "x4           14\n",
       "x5           14\n",
       "x6          927\n",
       "x7         2939\n",
       "x8         2677\n",
       "x9           31\n",
       "x10          14\n",
       "x11          14\n",
       "x12          14\n",
       "x13          14\n",
       "x14          25\n",
       "x15          41\n",
       "x16          64\n",
       "x17          64\n",
       "x18          17\n",
       "x19          17\n",
       "x20          17\n",
       "x21          55\n",
       "x22          17\n",
       "x23          17\n",
       "x24          49\n",
       "x25          23\n",
       "x26          17\n",
       "x27          17\n",
       "x28         100\n",
       "x29         354\n",
       "x30          17\n",
       "x31          90\n",
       "x32          17\n",
       "x33          17\n",
       "x34          17\n",
       "x35          17\n",
       "x36          17\n",
       "x37          25\n",
       "x38          25\n",
       "x39          25\n",
       "x40          25\n",
       "x41          25\n",
       "x42          25\n",
       "x43          25\n",
       "x44          25\n",
       "x45          25\n",
       "x46          25\n",
       "x47          25\n",
       "x48          25\n",
       "x49          25\n",
       "x50       24445\n",
       "target        0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(train_data == -999).sum(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "4df9b574-16a1-47cf-bfa3-19b9e7006b63",
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.10/site-packages/sklearn/linear_model/_logistic.py:458: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  n_iter_i = _check_optimize_result(\n",
      "/usr/local/lib/python3.10/site-packages/sklearn/linear_model/_logistic.py:458: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  n_iter_i = _check_optimize_result(\n",
      "/usr/local/lib/python3.10/site-packages/sklearn/linear_model/_logistic.py:458: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  n_iter_i = _check_optimize_result(\n",
      "/usr/local/lib/python3.10/site-packages/sklearn/linear_model/_logistic.py:458: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  n_iter_i = _check_optimize_result(\n",
      "/usr/local/lib/python3.10/site-packages/sklearn/linear_model/_logistic.py:458: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
      "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
      "\n",
      "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
      "    https://scikit-learn.org/stable/modules/preprocessing.html\n",
      "Please also refer to the documentation for alternative solver options:\n",
      "    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
      "  n_iter_i = _check_optimize_result(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0    0.99843   0.99794   0.99818    169980\n",
      "           1    0.98837   0.99111   0.98974     30020\n",
      "\n",
      "    accuracy                        0.99691    200000\n",
      "   macro avg    0.99340   0.99452   0.99396    200000\n",
      "weighted avg    0.99692   0.99691   0.99692    200000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import LogisticRegression\n",
    "from sklearn.model_selection import cross_val_predict\n",
    "from sklearn.metrics import classification_report\n",
    "\n",
    "pred = cross_val_predict(\n",
    "    LogisticRegression(max_iter=100),\n",
    "    train_data.drop(['id', 'target'], axis=1),\n",
    "    train_data['target']\n",
    ")\n",
    "\n",
    "print(classification_report(train_data['target'], pred, digits=5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3106a811-99ea-462d-a6c6-1335c7304ecc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0    0.99991   0.99986   0.99989    169980\n",
      "           1    0.99923   0.99950   0.99937     30020\n",
      "\n",
      "    accuracy                        0.99981    200000\n",
      "   macro avg    0.99957   0.99968   0.99963    200000\n",
      "weighted avg    0.99981   0.99981   0.99981    200000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.model_selection import cross_val_predict\n",
    "from sklearn.metrics import classification_report\n",
    "\n",
    "pred = cross_val_predict(\n",
    "    DecisionTreeClassifier(),\n",
    "    train_data.drop(['id', 'target'], axis=1),\n",
    "    train_data['target']\n",
    ")\n",
    "\n",
    "print(classification_report(train_data['target'], pred, digits=5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "0483ef0e-e4f6-4a03-9ade-ee42c59fe398",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "              precision    recall  f1-score   support\n",
      "\n",
      "           0    0.99996   0.99998   0.99997    169980\n",
      "           1    0.99990   0.99980   0.99985     30020\n",
      "\n",
      "    accuracy                        0.99996    200000\n",
      "   macro avg    0.99993   0.99989   0.99991    200000\n",
      "weighted avg    0.99995   0.99996   0.99995    200000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from lightgbm import LGBMClassifier\n",
    "from sklearn.model_selection import cross_val_predict\n",
    "from sklearn.metrics import classification_report\n",
    "\n",
    "pred = cross_val_predict(\n",
    "    LGBMClassifier(),\n",
    "    train_data.drop(['id', 'target'], axis=1),\n",
    "    train_data['target']\n",
    ")\n",
    "\n",
    "print(classification_report(train_data['target'], pred, digits=5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "0faef56a-b54c-4952-b593-5fe3a710acb0",
   "metadata": {},
   "outputs": [],
   "source": [
    "model = LGBMClassifier().fit(train_data.drop(['id', 'target'], axis=1), train_data['target'])\n",
    "pred = model.predict(test_data.drop(['id'], axis=1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "75e3fb45-45d2-452c-9182-430c2f62fdbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "pd.DataFrame({'id': test_data['id'], 'target': pred}).to_csv('a.csv', index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d6c4a83-39b0-48e4-807f-caf8c59c5f4a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
